import pygame, random, math, sys
from pygame.locals import *

class BikeSprite(pygame.sprite.Sprite):
    normal = pygame.image.load('../../Desktop/image_files/bike_bikini.png')
    turning_left = pygame.image.load('../../Desktop/image_files/bike_bikini_minus15.png')
    turning_right = pygame.image.load('../../Desktop/image_files/bike_bikini_plus15.png')    
    speed = 1
    
    def __init__(self, position):
        pygame.sprite.Sprite.__init__(self)
        self.rect = pygame.Rect(self.normal.get_rect())
        self.rect.center = position
        self.image = self.normal
        
    def update(self, dir):
        if dir == "L":
            self.image = self.turning_left 
        elif dir == "R":
            self.image = self.turning_right
        else:
            self.image = self.normal 

def startGame(width, height, caption):
    pygame.init()
    pygame.font.init()
    random.seed()
    global screen
    screen = pygame.display.set_mode((width, height))
    pygame.display.set_caption(caption)
    global clock
    clock = pygame.time.Clock()

running = True
width = 500
height = 500
k_up = k_down = k_left = k_right = 0 
dir_x = 250
dir_y = 250
startGame(width, height, 'PySnake')

bikes = pygame.sprite.RenderClear()
bikes.add(BikeSprite((250, 250)))

while running:
    clock.tick(30)
    screen.fill((0,0,0))
    dir = ""
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
        if not hasattr(event, 'key'):
            continue        
        if event.key == K_RIGHT:            
            dir_x = dir_x + 5
            dir = "R"
        elif event.key == K_LEFT:            
            dir_x = dir_x - 5  
            dir = "L"     
    
    bikes.update(dir)
    bikes.draw(screen)
    pygame.display.flip()